﻿open System
open System.Data
open System.Data.OleDb
open System.Drawing
open System.Windows.Forms
open PoliticalClassifier.PlotGenerator
open PoliticalClassifier.Support

let randomPoints =
    seq {
        let rand = Random()
        for i in 1 .. 8000 do
            yield Point2D (2.0 * (rand.NextDouble() + rand.NextDouble() + rand.NextDouble() + rand.NextDouble() + rand.NextDouble() + rand.NextDouble()) / 6.0 - 1.0, 
                2.0 * (rand.NextDouble() + rand.NextDouble() + rand.NextDouble() + rand.NextDouble() + rand.NextDouble() + rand.NextDouble()) / 6.0 - 1.0)
        }
    |> Seq.toArray

let pathToExcelFile = @"C:\Users\Jonathan.DeCarlo\Desktop\Social_Economic_DataMicro.xlsx"
let connectionString = String.Format ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}; Extended Properties=Excel 12.0;", pathToExcelFile)

let voterDataTable = 
    use adapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", connectionString)
    let ds = new DataSet()
    adapter.Fill (ds, "voterDataTable") |> ignore
    ds.Tables.["voterDataTable"]

let voterDataPoints =
    let getRowValue (row : DataRow) (columnName : string) =
        match row.IsNull columnName with
        | true -> 0.0
        | false -> unbox(row.[columnName])
    voterDataTable.Rows
    |> Seq.cast
    |> Seq.map (fun (row : DataRow) -> (getRowValue row "inc", getRowValue row "age"))
    |> Seq.map (function x, y -> Point2D(x, y))
    |> Seq.toArray

[<EntryPoint>]
let main argv = 
    let plotRange = Range2D(-1.0, 1.0, -1.0, 1.0)
    let radiusOfPointCircle = 0.025
    let mockSimulationResults = {
        new ISimulationResults with 
            member this.NormalizationScale = 1
            member this.OverallVoterMedianPoint = Point2D(0.0, 0.0)
            member this.CandidateResults = null
        }
    let image = PlotGenerator().CreatePlotImage (mockSimulationResults.OverallVoterMedianPoint, randomPoints, plotRange, radiusOfPointCircle)
    use form = new Form()
    let pictureBox = new PictureBox()
    form.Controls.Add pictureBox
    form.ClientSize <- Size(image.Size.Width, image.Size.Height)
    form.StartPosition <- FormStartPosition.CenterScreen
    pictureBox.Image <- image
    pictureBox.Dock <- DockStyle.Fill
    form.ShowDialog() |> ignore
    0 // return an integer exit code
